package com.atguigu.springboot.controller;

import com.atguigu.springboot.exception.UserNotExistsException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Map;

/**
 * @author : leimingchao
 * @date Date : 2021年08月15日 20:59
 */
@Controller
public class HelloController {

    // @RequestMapping(value = {"/","/index.html"})
    // public String index() {
    //     return "index";
    // }

    @RequestMapping(value = "/hello")
    @ResponseBody
    public String hello(@RequestParam(value = "user") String user) {
        if ("aaa".equals(user)) {
            throw new UserNotExistsException();
        }
        return "Hello World";
    }

    //查出一些数据，在页面展示
    @RequestMapping(value = "/success")
    public String success(Map<String,Object> map) {
        //classpath:/templates/success.html
        map.put("hello","<h1>你好</h1>");
        map.put("users",Arrays.asList("zhangsan","lisi","wangwu"));
        return "success";
    }
}
